package com.konsung.ksdc.manager.addr;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.AddrAdvanceBean;
import com.konsung.ksdc.config.MyApplication;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DistrictCityAdapter extends BaseAdapter {

    private List<AddrAdvanceBean> mDatas = new ArrayList<>();
    private Activity activity;

    /**
     *
     * @param activity 类
     * @param datas 数据
     * @param provinceName 名字
     */
    public DistrictCityAdapter(Activity activity, List<AddrAdvanceBean>
            datas, String provinceName) {
        mDatas = datas;
        this.activity = activity;
    }


    @Override
    public int getCount() {
        if (mDatas != null) {
            return mDatas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final AddrAdvanceBean bean = mDatas.get(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout.item_listview_area, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        convertView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(activity, DistrictStep3.class);
//                intent.putExtra(DistrictStep2.COUNTY_DATA, bean);
//                intent.putExtra(DistrictStep2.CITY_NAME,provinceName + bean
//                        .getAreaName());
//                activity.startActivity(intent);
//            }
//        });
        String cityName = bean.getAreaName();

        holder.tvCity.setText(cityName);

        return convertView;
    }

    /***
     * 内部类
     */
    static class ViewHolder {
        @Bind(R.id.tv_area_name)
        TextView tvCity;
    }
}
